<?php

class PayvmentServiceWrapper {

    private $service = null;

    public static $apiKey = null;
    public static $payvmentID = null;

    public function __construct($currency = 'EUR') {
        $this->service = new PayvmentService(self::$apiKey,self::$payvmentID,$currency);
    }

    public function addStoreItem(Product $product, $itemQty, $itemOptions = array()) {
        if (!Cookie::get('CartID'))
            Cookie::set('CartID',$service->createNewCartID);

        if ($itemQty <= 0)
            $itemQty = 1;

        $itemShipping = array();
        if ($product->ItemNoShip == false) {
            $itemShipping = false;
        }
        else {
            if ($product->ItemShipping2 && $product->ItemShipping) {
                $itemShipping[0] = $product->ItemShipping;
                $itemShipping[1] = $product->ItemShipping2;
            }
            elseif ($product->ItemShipping) {
                $itemShipping[0] = $product->ItemShipping;
            }
        }

        $result = $service->addStoreItem(Cookie::get('CartID'),$product->ItemCurrency,$product->ItemID,$product->Title,$product->ItemPrice,$itemQty,$product->Link(),$itemShipping, $itemOptions);
    }

    public function updateStoreItem(Product $product, $itemQty, $itemOptions = array()) {
        if (!Cookie::get('CartID'))
            Cookie::set('CartID',$service->createNewCartID);

        if ($itemQty <= 0)
            $itemQty = 1;

        $resutl = $this->service(Cookie::get('CartID'),$product->ItemID,$itemQty,$itemOptions);
    }

    public function deleteStoreItem(Product $product, $itemOptions = array()) {
        if (!Cookie::get('CartID'))
            Cookie::set('CartID',$service->createNewCartID);

        $result = $service->deleteStoreItem(Cookie::get('CartID'),$product->ItemID,$itemOptions);
    }
}
